package cn.com.view;

import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Date;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;

import cn.com.action.BoolBarAction;
import db.JDBConnection;


public class MainFrame extends JFrame{
	
	private static MainFrame frame;

	BoolBarAction action = new BoolBarAction(this);

	JPanel panel = new JPanel();

	public JTextField startDate;

	public JTextField endDate;

	public static final String	CENTER	= "Center";

	/**
	 * 构造方法
	 */
	public MainFrame() {
		super("修改日期");
		// 初始化窗体
			init();
	}

	/**
	 * 初始化
	 */
	private void init() {
		this.setSize(300, 300);// 设置窗体大小
		this.add(createJScrollPane(), MainFrame.CENTER);
		this.setDefaultCloseOperation(2);// 设置窗体关闭模式
		this.setLocationRelativeTo(null);// 窗体居中
		this.setVisible(true);// 窗体可见
		
		this.addWindowListener(new WindowAdapter(){
			@Override
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}

	/**
	 * 创建流动面板
	 * @return
	 */
	public JPanel createJScrollPane() {

		startDate = new JTextField();
		endDate = new JTextField();

		JLabel dmLabel = new JLabel("开始日期");
		dmLabel.setBounds(30, 30, 100, 30);
		JLabel dateLabel = new JLabel("结束日期");
		dateLabel.setBounds(30, 100, 100, 30);

		panel.setLayout(null);
		startDate.setBounds(100, 30, 150, 30);
		startDate.setMinimumSize(new Dimension(100,100));
		startDate.setEditable(true);

		endDate.setBounds(100, 100, 150, 30);
		endDate.setEditable(true);

		panel.add(dmLabel);
		panel.add(dateLabel);
		panel.add(startDate);
		panel.add(endDate);

		JButton updataButton = createJbutton("确定");
		updataButton.setBounds(100, 170, 50, 30);

		JButton closeButton = createJbutton("取消");
		closeButton.setBounds(200, 170, 50, 30);

		panel.add(updataButton);
		panel.add(closeButton);
		return panel;
	}

	/**
	 * 创建按钮
	 * @param title 标题
	 * @return 返回一个按钮
	 */
	public JButton createJbutton(String title) {
		JButton button = new JButton(title);
		button.addActionListener(action);
		button.setMargin(new Insets(0, 0, 0, 0));
		return button;
	}

	public synchronized static MainFrame open() {
		// TODO Auto-generated method stub
		if(frame == null){
			frame = new MainFrame();	
		}
		return frame;
	}


	
	public static MainFrame getFrame() {
		return frame;
	}

	
	public static void setFrame(MainFrame frame) {
		MainFrame.frame = frame;
	}

	
	public JTextField getStartDate() {
		return startDate;
	}

	
	public void setStartDate(JTextField startDate) {
		this.startDate = startDate;
	}

	
	public JTextField getEndDate() {
		return endDate;
	}

	
	public void setEndDate(JTextField endDate) {
		this.endDate = endDate;
	}

}
